﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Data.ConnectionUI;
using System.Windows.Forms;

namespace SN.Services
{
    /// <summary>
    /// 连接数据库对话框
    /// </summary>
   public static class ConnectDialog
    {
        public static string[] showConnectionDialog(Microsoft.Data.ConnectionUI.DataSource dataSource, DataProvider dataProvider)
        {
            DataConnectionDialog dcdig = new DataConnectionDialog();
            DataSource.AddStandardDataSources(dcdig);
            if (dataSource != null)
            {
                dcdig.SelectedDataSource = dataSource;
                if (dataProvider != null)
                {
                    dcdig.SelectedDataProvider = dataProvider;
                }
            }
            if (DataConnectionDialog.Show(dcdig) == DialogResult.OK)
            {
                return new string[] { dcdig.ConnectionString, dcdig.SelectedDataProvider.Name };
            }
            return null;
        }

        public static string[] showSqlConnectionDialog()
        {
            return showConnectionDialog(DataSource.SqlDataSource, DataProvider.SqlDataProvider);
        }
    }
}
